package fem2d;

import fem2.AbstractStructuralStaticDemo;
import fem2.Element;
import fem2.MaterialModel;
import fem2.MeshPart;
import fem2.Model;
import fem2.Observer;
import fem2.StringUtilities;
import fem2.element.EASStructuralElement;
import fem2.element.StructuralElement;
import fem2.enu.EASModeType;
import fem2.enu.StressType;
import fem2.observer.GidDisplacementObserver;
import fem2.observer.GidResistantObserver;
import fem2.observer.GidStressObserver;
import fem2.observer.TimeStepObserver;
import fem2.observer.TimingObserver;
import fem2.pre_and_post.GidPostStructural;
import fem2.strategies.Strategy;

/**
 * slope analysis with bbar element and StVenantKrirchoff material
 * 
 * @author hbui
 * 
 */
public class SlopeStabilityIncompatibleMode extends SlopeStability {

	public SlopeStabilityIncompatibleMode() {
		// meshFileName = "hyplas-mesh.msh"; // 8-node quadrilateral mesh //bad
		// result
		// meshFileName = "mesh1.msh"; // 4-node quadrilateral mesh
		// meshFileName = "mesh2.msh"; // 6-node triangle mesh //good result
		// meshFileName = "mesh3.msh"; // 3-node triangle mesh
		// meshFileName = "abaqus-mesh-bbar.msh"; // 8-node quadrilateral mesh
		// good result with bbar element
		meshFileName = "abaqus-q4-mesh-incompatible.msh"; // 4-node
															// quadrilateral
															// mesh
		// wrong recover stress. TODO Need check
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm) {
		StructuralElement e = new EASStructuralElement(mp, mm, EASModeType.Q1E4);
		return e;
	}

	@Override
	public void addObservers(Model m, Strategy s, TimeStepObserver o) {
		if (meshFileName == null) {
			throw new Error("mesh file name was not set");
		}

		/*
		 * clean all previous post files
		 */
		String meshName = StringUtilities.getFileName(meshFileName);

		GidPostStructural post = new GidPostStructural(projectDir, projectName, meshName);
		post.clearAllPostFiles();

		Observer so = new GidStressObserver(m, o, projectDir, projectName, meshName,
				StressType.RECOVER_STRESS_EAS);

		// Observer ro1 = new ResistantGraphicalObserver(m, s,
		// getNodesForResistantObserver(m));
		Observer ro2 = new GidResistantObserver(m, o, projectDir, projectName, meshName);

		Observer do1 = new GidDisplacementObserver(m, o, projectDir, projectName, meshName);

		s.addObserver(so);
		// s.addObserver(ro1);
		s.addObserver(ro2);
		s.addObserver(do1);
		s.addObserver(new TimingObserver());
	}

	public static void main(String[] args) {
		AbstractStructuralStaticDemo demo = new SlopeStabilityIncompatibleMode();

		demo.run();
	}
}
